jQuery(document).ready(function(){

        var folder = 'tempatt/';

        var uploader = new plupload.Uploader({

                runtimes: 'flash',
                flash_swf_url: base_url+'assets/js/plupload/plupload.flash.swf',
                browse_button: 'plupload-browse-button ',
                container: 'plupload-upload-ui',
                url: base_url+'assets/js/plupload/upload.php',
                multipart : false,
                multipart_params: { 'datafield': folder },
                unique_names: false ,
                /*resize : { quality : 80},  */
                // Specify what files to browse for
                filters : [
                    {title : "Image files", extensions : "jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG"}
                ]

        });

        uploader.settings.multipart_params.datafield = folder;    

        uploader.init();

        uploader.bind('FilesAdded', function(up, files) {        
                // loop through the files array
                for (var i in files) {            
                    document.getElementById('uploadQueue').innerHTML += '<div id="' + files[i].id + '">[<a href="javascript:">remove</a>] ' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';            
                }
        });

        uploader.bind('UploadProgress', function(up, file) {        
                document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";        
        });

        uploader.bind('Error', function(up, args) {        
                alert(args.code + ': ' + args.message);        
        });

        document.getElementById('plupload_btn').onclick = function() { 

            if(jQuery('#uploadQueue').children().length==0){
                alert('Please select files to upload')
                return false;
            }

            /*if(jQuery('#galleryselect').val()==0){
            alert('Please choose gallery')
            return false;
            }*/

            jQuery(this).attr('disabled','disabled');
            jQuery('.status_info').html('Please wait while images are being uploaded');

            uploader.start();         
        };

        uploader.bind('BeforeUpload', function(up, file) {

                up.settings.url =  base_url+'assets/js/plupload/upload.php'+"?gellery_path="+pro_gallery+"/"+object_gallery_folder+'/';
        });


        uploader.bind('FileUploaded', function(up, file, info) {                      

                var obj = jQuery.parseJSON(info.response);                        

                jQuery('#uploadimage_form').append('<input type="hidden" name="pictures[]" value="'+obj.datafield+'" />');
                jQuery('#uploadimage_form').append('<input type="hidden" name="pic_titles[]" value="'+file.name+'" />');

                if( (uploader.total.uploaded) == uploader.files.length) {

                    jQuery('.status_info').html('Creating thumbnails :: Please wait');
                    jQuery('#uploadimage_form').submit();

                };

        });

        jQuery('#uploadQueue a').live('click', function(){

                jQuery(this).parent().fadeOut('slow').remove();
        })


});